package com.wsy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wsy.entity.Emp;
import com.wsy.mapper.EmpMapper;
import com.wsy.service.EmpService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp> implements EmpService {
    @Resource
    EmpMapper empMapper;


    @Override
    public PageInfo<Emp> select(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<Emp>(empMapper.select());
    }

    @Override
    public int addEmp(Emp emp) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        emp.setEmpPwd(encoder.encode("123"));
        return empMapper.addEmp(emp);
    }

    @Override
    public int updEmp(Emp emp) {
        return empMapper.updEmp(emp);
    }

    @Override
    public int delEmp(Emp emp) {
        emp.setState(1);
        return empMapper.delEmp(emp);
    }
}
